package test04datainput;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

import static test04datainput._FileinputStream._FileUtil.readFile;

public class _FileinputStream {
    public static void main(String[] args) throws Exception {
        //练习七：找一个文件利用字节输入流读取出来内容
        String filePath = "/test.txt";
        readFile(filePath);
    }

    public class _FileUtil {
        public static void readFile(String filePath) {
            try (
                    //使用相对路径在resources下获取流
                    InputStream inputStream = _FileUtil.class.getResourceAsStream(filePath);
                    //使用缓冲流
                    BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {

                String line;
                while ((line = reader.readLine()) != null) {
                    System.out.println(line);
                }

            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }
}
